package com.leetcode.ask;

public class Number198 {
    public static void main(String[] args) {
        int s[] = new int[]{1, 3, 2, 1, 5, 6};
        System.out.println(rob(s));
    }

    public static int rob(int[] nums) {
        if (nums.length <= 0) return 0;
        if (nums.length == 1) return nums[0];
        int[] numsRet = new int[nums.length];
        numsRet[0] = nums[0];
        numsRet[1] = Math.max(nums[0], nums[1]);
        for (int i = 2; i < nums.length; i++) {
            numsRet[i] = Math.max(numsRet[i - 2] + nums[i], numsRet[i - 1]);
        }
        return numsRet[numsRet.length - 1];
    }
}
